package com.scs.application.core.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.scs.application.core.utils.StringUtils;
import com.scs.application.modules.upgrade.db.annotation.EntityFieldAnnotation;
import com.scs.application.modules.upgrade.db.enums.EntityFieldType;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;
/**
 * @Description： 数据对象
 */
@JsonIgnoreProperties(value="newRecord", allowGetters = false, allowSetters = false)
@Data
@EqualsAndHashCode(callSuper = false)
@ToString(exclude = {"creator", "gmtCreate", "modifier", "gmtModified"})
@Accessors(chain = true)
public class DataEntity extends BaseEntity implements Serializable {
    @EntityFieldAnnotation(
            type = EntityFieldType.LONG
    )
    @TableId(type = IdType.ID_WORKER_STR)
    public String id;

    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @JSONField(deserialize = false)
    @TableField(value = "creator", fill = FieldFill.INSERT)
    @EntityFieldAnnotation(
            length = "30"
    )
    public String creator;

    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @JSONField(deserialize = false)
    @TableField(value = "gmt_create", fill = FieldFill.INSERT)
    public LocalDateTime gmtCreate;

    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @JSONField(deserialize = false)
    @TableField(value = "modifier", fill = FieldFill.INSERT_UPDATE)
    @EntityFieldAnnotation(
            length = "30"
    )
    public String modifier;

    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @JSONField(deserialize = false)
    @TableField(value = "gmt_modified", fill = FieldFill.INSERT_UPDATE)
    public LocalDateTime gmtModified;

//    @TableField(value = "remarks")
//    private String remarks;


//    @JSONField(name = "creator", deserialize = false)
//    public String getCreatorName() {
//    	if(StringUtils.isBlank(this.creator)) {
//    		return null;
//    	}
//
////    	User user = (User)CacheUtils.get(CacheConsts.SYS_USER_CODE_PREFIX + this.creator);
////    	return user != null ? user.getName() : this.creator;
//    }
//
//    @JSONField(name = "modifier", deserialize = false)
//    public String getModifierName() {
//    	if(StringUtils.isBlank(this.modifier)) {
//    		return null;
//    	}
//
//    	User user = (User)CacheUtils.get(CacheConsts.SYS_USER_CODE_PREFIX + this.modifier);
//    	return user != null ? user.getName() : this.modifier;
//    }


    @JsonIgnore
    @JSONField(serialize = false,deserialize = false)
    public boolean isNewRecord(){
        return StringUtils.isBlank(id);
    }

}
